<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>promise.race</title>
  </head>
  <body></body>
  <script>
    //哪个promise状态先完成（哪个快），promise.race就用哪个
    let houdunren = new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve("第一个异步");
        // reject("fail");
      }, 1000);
    });
    let hdcms = new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve("第二个异步");
      }, 2000);
    });
    Promise.race([houdunren, hdcms])
      .then((result) => {
        console.log(result);
      })
      .catch((error) => {
        console.log(error);
      });
  </script>
</html>
